﻿@Code
    Layout = "~/_SiteLayout.vbhtml"
    
    Dim db = Database.Open("CalibreDB")
    
    Dim id = UrlData(0).AsInt()
    Dim sqlStr = "SELECT books.id, books.title, books.author_sort, books.[timestamp] AS titledate, books.pubdate, books.last_modified, " _
                    & "books.series_index, books.has_cover, languages.lang_code, publishers.name AS publisher, series.name AS series, " _
                    & "ratings.rating / 2 AS rating, comments.text AS comments FROM books LEFT JOIN " _
                    & "books_languages_link ON books.id = books_languages_link.book LEFT JOIN " _
                    & "languages ON books_languages_link.lang_code = languages.id LEFT JOIN " _
                    & "books_publishers_link ON books.id = books_publishers_link.book LEFT JOIN " _
                    & "publishers ON books_publishers_link.publisher = publishers.id LEFT JOIN " _
                    & "books_series_link ON books.id = books_series_link.book LEFT JOIN " _
                    & "series ON books_series_link.series = series.id LEFT JOIN " _
                    & "books_ratings_link ON books.id = books_ratings_link.book LEFT JOIN " _
                    & "ratings ON books_ratings_link.rating = ratings.id LEFT JOIN " _
                    & "comments ON books.id = comments.book WHERE (books.id = @0)"
    
    Dim book = db.QuerySingle(sqlStr, id)
    
    If book Is Nothing Then
        Response.Redirect("~/List/")
    End If
   
    PageData("Title") = book.Title.ToString
    
    Dim formats = LibCalibreVB.GetFormats(id)
    Dim authors = LibCalibreVB.GetAuthors(id)
    Dim ids = LibCalibreVB.GetIds(id)
    Dim tags = LibCalibreVB.GetTags(id)
    Dim series = LibCalibreVB.GetSeries(id)
        
End Code

<div class="container">
    <div class="row">
        <div class="metro span9">
            <h2>@book.Title</h2>
            <br />
            @CalibreHelpers.FormatTable("Formats", formats, id)
            @CalibreHelpers.FormatString("Author Sort", book.author_sort)
            @CalibreHelpers.FormatTable("Authors", authors, id)
            <p><b>Date</b>: @String.Format("{0:dd MMM yyyy}", book.titledate)</p>
            @CalibreHelpers.FormatTable("IDs", ids, id)
            @CalibreHelpers.FormatHyperlink("Languages", book.lang_code)
            <p><b>Modified</b>: @String.Format("{0:dd MMM yyyy}", book.last_modified)</p>
            <p><b>Published</b>: @String.Format("{0:MMM yyyy}", book.pubdate)</p>
            @CalibreHelpers.FormatString("Publisher", book.publisher)
            @CalibreHelpers.FormatHyperlink("Rating", book.rating)
            @CalibreHelpers.FormatTable("Series", series, id)
            @CalibreHelpers.FormatTable("Tags", tags, id)
        </div>
        <div class="metro span3">
            @CalibreHelpers.FormatCover(book.title, book.has_cover, id, "large")
        </div>
        <div class="metro span12">
            @CalibreHelpers.FormatString("Summary", book.comments)
      </div>
    </div>
</div>

